package com.tank.jdk8;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.util.Optional;
import java.util.Spliterator;

/**
 * Created with IntelliJ IDEA.
 * User: SuQiEr
 * Date:2017/1/16
 * Time: 19:19
 * To change this template use File | Settings | File Templates.
 */
@Slf4j
public class OptionalTest {


    @Test
    public  void test(){


        Integer a = null;

        Integer b = new Integer(1);

        Optional<Integer> optional = Optional.ofNullable(a);

        Optional<Integer> optional1 = Optional.of(b);

        log.info("sum:{}",sum(optional,optional1));
    }

    public static Integer sum(Optional<Integer> optional,Optional<Integer> optional2){

        log.info("optional is present:{}",optional.isPresent());
        log.info("optional2 is present:{}",optional2.isPresent());

        Integer a = (Integer) optional.orElse(new Integer(0));

        Integer b = optional2.get();

        return a +b ;


    }
}

